import 'package:aio/aio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:app/generated/app_strings.dart';
import 'package:app/src/http/bean/wroks/contract_bean.dart';
import 'package:app/src/ui/route/works/public/items/ui_base.dart';
import 'package:app/src/ui/route/works/public/items/ui_card.dart';

import '../../../../../http/bean/works_2023/contractroyaltyrateapplycheck_bean.dart';
import '../../../../dialog/dailog.dart';

///合同信息（基本信息）
class UiContractInfo {
  ///data 信息
  ///oldData 历史信息
  static Widget build(
      BuildContext context, ContractCopyInfo? data, ContractCopyInfo? oldData,
      {String? title,
      ContractRoyaltyRateApplyCheckBean? ContractRoyaltyRateApplyCheck =
          null}) {
    List<Widget> children = [];
    if (StringUtils.isEmpty(title)) {
      title = AppStrings.of(context).BaseInfo; //基本信息
    }
    children.add(UiBase.title(context, title)); //标题
    children.add(UiBase.item(context, AppStrings.of(context).ContractCode,
        data?.ContractCode, oldData?.ContractCode)); //合同编号

    // children.add(UiBase.itemWithEdit(context, AppStrings.of(context).ContractCode,
    //     data?.ContractCode, oldData?.ContractCode,isNumber: true,isDecimal: false)); //合同编号 fixme 测试文本输入框

    // children.add(UiBase.item(context, AppStrings.of(context).OutCode,
    //     data?.OutCode, oldData?.OutCode,unit: AppStrings.of(context).Detailedallocation)); //测试

    children.add(UiBase.item(context, AppStrings.of(context).OutCode,
        data?.OutCode, oldData?.OutCode)); //合同外部编号
    children.add(UiBase.item(context, AppStrings.of(context).ProjectName,
        data?.ProjectName, oldData?.ProjectName)); //项目名称
    children.add(UiBase.item(context, AppStrings.of(context).CustomerName,
        data?.CustomerName, oldData?.CustomerName)); //客户名称
    children.add(UiBase.item(context, AppStrings.of(context).SignDate,
        data?.SignDate, oldData?.SignDate)); //签订日期
    children.add(UiBase.item(context, AppStrings.of(context).CompleteDate,
        data?.CompleteDate, oldData?.CompleteDate)); //完结日期
    children.add(UiBase.item(context, AppStrings.of(context).CreditMonth,
        data?.CreditMonth, oldData?.CreditMonth)); //合同金额
    children.add(UiBase.item(context, AppStrings.of(context).ContractTypeName,
        data?.ContractTypeName, oldData?.ContractTypeName)); //合同类型
    children.add(UiBase.item(context, AppStrings.of(context).Address,
        data?.Address, oldData?.Address)); //联系地址
    children.add(UiBase.item(context, AppStrings.of(context).LinkMan,
        data?.LinkMan, oldData?.LinkMan)); //联系人
    children.add(UiBase.item(context, AppStrings.of(context).Telephone,
        data?.Telephone, oldData?.Telephone)); //联系电话
    children.add(UiBase.item(
        context, AppStrings.of(context).Fax, data?.Fax, oldData?.Fax)); //传真
    children.add(UiBase.item(context, AppStrings.of(context).PackageName,
        data?.PackageName, oldData?.PackageName)); //包装要求
    children.add(UiBase.item(
        context,
        AppStrings.of(context).DeliveryMethodsName,
        data?.DeliveryMethodsName,
        oldData?.DeliveryMethodsName)); //发货要求
    children.add(UiBase.item(context, AppStrings.of(context).AccountMethods,
        data?.AccountMethods, oldData?.AccountMethods)); //结算要求
    children.add(UiBase.item(context, AppStrings.of(context).CompanyName,
        data?.CompanyName, oldData?.CompanyName)); //销售公司
    children.add(UiBase.item(context, AppStrings.of(context).QualityTypeName,
        data?.QualityTypeName, oldData?.QualityTypeName)); //质量标准
    children.add(UiBase.item(context, AppStrings.of(context).PrintMoneyName,
        data?.PrintMoneyName, oldData?.PrintMoneyName)); //打印单价
    children.add(UiBase.item(context, AppStrings.of(context).IsForeignName,
        data?.IsForeignName, oldData?.IsForeignName)); //是否外贸
    children.add(UiBase.item(context, AppStrings.of(context).SalesmanName3,
        data?.SalesmanName, oldData?.SalesmanName)); //业务经理
    if (ContractRoyaltyRateApplyCheck != null) {
      //业务提成
      var data = ContractRoyaltyRateApplyCheck;
      var oldData=data;
      children.add(UiBase.item(
          context,
          AppStrings.of(context).Businesscommission,
          "${data?.SalesmanRoyaltyRate}" + "%",
          "${oldData?.SalesmanRoyaltyRate}%",
          sufix: InkWell(
            child: Text(
              "\t${AppStrings.of(context).Detailedallocation}\t",
              style: TextStyle(color: Colors.blueAccent),
            ),
            onTap: () {
              //fixme 详情分配=====================================================
              String? content = data?.ModifyContractRoyaltyRate
                  ?.getMerchandiserRoyaltyContent(context);
              if (!StringUtils.isEmpty(content)) {
                AppDialog.showDialogWithInfo(context, content: content);
              }
            },
          ))); //fixme 业务提成（字段需要对接接口）
    }
    children.add(UiBase.item(context, AppStrings.of(context).MerchandiserName,
        data?.MerchandiserName, oldData?.MerchandiserName)); //客服经理
    if (ContractRoyaltyRateApplyCheck != null) {
      //客服提成
      var data = ContractRoyaltyRateApplyCheck;
      var oldData=data;
      children.add(UiBase.item(
          context,
          AppStrings.of(context).Customerservicecommission,
          "${data?.MerchandiserRoyaltyRate}%",
          "${oldData?.MerchandiserRoyaltyRate}%")); //fixme 客服提成(字段需要对接接口)
    }
    children.add(UiBase.item(context, AppStrings.of(context).CurrencyTypeName,
        data?.CurrencyTypeName, oldData?.CurrencyTypeName)); //结算货币
    children.add(UiBase.item(context, AppStrings.of(context).AbnormityAreaName,
        data?.AbnormityAreaName, oldData?.AbnormityAreaName)); //异形面积
    children.add(UiBase.item(
        context,
        AppStrings.of(context).AdvanceOffsetModeName,
        data?.AdvanceOffsetModeName,
        oldData?.AdvanceOffsetModeName)); //冲抵方式
    children.add(UiBase.item(context, AppStrings.of(context).TaxCode,
        data?.TaxCode, oldData?.TaxCode)); //税码
    children.add(UiBase.item(context, AppStrings.of(context).TaxRate,
        data?.TaxRate, oldData?.TaxRate)); //结算税率
    children.add(UiBase.item(context, AppStrings.of(context).BkCode,
        data?.BkCode, oldData?.BkCode)); //开户行
    children.add(UiBase.item(context, AppStrings.of(context).BkAccountNum,
        data?.BkAccountNum, oldData?.BkAccountNum)); //银行账户
    children.add(UiBase.item(context, AppStrings.of(context).GlueDeepType,
        data?.GlueDeepType, oldData?.GlueDeepType)); //中空胶深
    children.add(UiBase.item(context, AppStrings.of(context).OtherGlueDeep,
        data?.OtherGlueDeep, oldData?.OtherGlueDeep)); //胶深数值
    var column = UiBase.column(context, children);
    var card = UiCard.build(context, column);
    return card;
  }
}
